package com.yuantu.judiciary.dao;

import com.yuantu.judiciary.model.domain.SysOperLogApiDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.sql.Timestamp;
import java.util.List;

/**
 * 日志
 *
 * @author syw
 * @since 2023-08-04
 **/
public interface ISysOperLogApiDao extends JpaRepository<SysOperLogApiDO, Long> {

    @Query("select o from SysOperLogApiDO o where o.deleted = false " +
            "and (:startTime is null or o.createTime >= :startTime) " +
            "and (:endTime is null or o.createTime <= :endTime) ")
    List<SysOperLogApiDO> findByCreateTimeAndDeletedFalse(Timestamp startTime, Timestamp endTime);

    @Query("select o from SysOperLogApiDO o where o.deleted = false " +
            "and (coalesce(:creatorIds, null) is null or o.creatorId in (:creatorIds)) " +
            "and (:startTime is null or o.createTime >= :startTime) " +
            "and (:endTime is null or o.createTime <= :endTime) ")
    List<SysOperLogApiDO> findByCreatorIdInAndCreateTimeAndDeletedFalse(List<Long> creatorIds, Timestamp startTime, Timestamp endTime);

}
